# 是否登陆
login_flg = False

# 当前登陆账号
login_account = ''

accounts = {'0001': {'password': '000000', 'money': 0},
            '0002': {'password': '888888', 'money': 100},
            '0003': {'password': '999999', 'money': 50}, }


# 登录陆
def login():
    global login_flg
    global login_account
    while True:
        account = input("请输入账号：")
        password = input("请输入密码：")
        if accounts.get(account) and accounts[account]['password'] == password:
            print('登陆成功!')
            login_flg = True
            login_account = account
            menu()
            break
        else:
            print('登陆失败,账号或密码错误。。。')


# 退出
def logout():
    global login_flg
    global login_account
    login_flg = False
    login_account = ''
    print('已退出登陆。。。')
    menu()


# 查询
def query():
    print('账户[{0}]的余额为 ：{1}元'.format(login_account, accounts[login_account]['money']))
    menu()


# 存款
def deposit():
    # 此处未进行数据类型检查（数字check，>0check等）
    money = int(input('请输入存款金额 : '))
    accounts[login_account]['money'] = accounts[login_account]['money'] + money
    print('存款成功。。。')
    menu()


# 取款
def withdraw():
    # 此处未进行数据类型检查（数字check，>0check等）
    money = int(input('请输入取款金额 : '))
    if accounts[login_account]['money'] - money < 0:
        print()
        print('可用余额不足，取款失败。。。')
    else:
        accounts[login_account]['money'] = accounts[login_account]['money'] - money
        print('取款成功。。。')
    menu()


# 菜单
def menu():
    global login_flg
    global login_account
    print("------------")
    print("请选择功能：")
    # 判断是否登陆
    if login_flg:
        print("0 存款")
        print("1 取款")
        print("2 查询")
        print("3 退出")
    else:
        # 未登陆的场合
        print("0 登陆")
    print("如需退出程序请输入'quit'")
    print("------------")
    while True:
        command = input('>>')
        if command == '0':
            if login_flg:
                deposit()
                break
            else:
                login()
                break
        elif command == '1':
            withdraw()
            break
        elif command == '2':
            query()
            break
        elif command == '3':
            logout()
            break
        elif command == 'quit':
            return
        else:
            print('输入错误，请重新输入。。。')


if __name__ == '__main__':
    menu()
